package com.putong35.common.web.ui;

import android.content.Intent;
import androidx.annotation.Keep;
import android.util.Log;
import android.webkit.JavascriptInterface;

import com.putong35.common.baseactfrag.fragment.BaseFragment;
import com.putong35.common.utils.AppUtil;
import com.putong35.common.utils.NetUtil;


/**
 * Created by Zoi.
 * E-mail：KyluZoi@gmail.com
 * 2016/7/28
 * 移动端接口的实现类
 */
public class MobileFunImpl implements MobileImpable {

    private BaseFragment mFragment;

    public MobileFunImpl(BaseFragment fragment) {
        mFragment = fragment;
    }

    @Keep
    @JavascriptInterface
    @Override
    public String getTokenInfo() {
        String token = null;
       /* if (AccountManager.isTokenValid()) {
            TokenInfo tokenInfo = AccountManager.getTokenInfo();
            token = GsonUtils.toJson(tokenInfo);
        }*/
        return token;
    }

    @Keep
    @JavascriptInterface
    @Override
    public void login() {
        Log.d("kyluzoi", "web use login");
    }

    @Keep
    @JavascriptInterface
    @Override
    public void uploadImage(String tag) {
        Log.d("kyluzoi", "web use uploadimage");
        /*PhotoAlertFragment photoAlertFragment = new PhotoAlertFragment();
        photoAlertFragment.show(getActivity().getFragmentManager(), "tag");
        photoAlertFragment.setOnCitySelectedListener(this);
        mSynTag = tag;*/
    }

    @Keep
    @JavascriptInterface
    @Override
    public void showToast(String url) {
//        return mConnectable.callback();
    }

    @Keep
    @JavascriptInterface
    @Override
    public void share(String title, String content, String imgUrl, String targetUrl) {
        Log.d("kyluzoi", "web use share");
        /*ShareData shareInfo = new ShareData(imgUrl, title, content, targetUrl);
        if (TextUtils.isEmpty(shareInfo.getImageUrl())) {
            shareInfo.setImageUrl("http://baidu.com");
        }*/
//      ShareHelper.share(getActivity(), MySharePlatformActivity.class, shareInfo, new MyShareListener());
//        ShareHelper.share(getActivity(), MySharePlatformActivity.class, shareInfo, new MyShareListener());
    }

    @Keep
    @JavascriptInterface
    @Override
    public void back() {
        mFragment.getActivity().finish();
    }

    @Keep
    @JavascriptInterface
    @Override
    public void showTabBar() {
    }

    @Keep
    @JavascriptInterface
    @Override
    public void hideTabBar() {
    }

    @Keep
    @JavascriptInterface
    @Override
    public boolean netIsAvalible() {
        return NetUtil.isAvalible(mFragment.getActivity());
    }

    @Keep
    @JavascriptInterface
    @Override
    public int getVersionCode() {
        return AppUtil.getVersionCode(mFragment.getActivity());
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {

    }
}
